<?php

/**
 * Editing a CRMUser
 * @package ModuleAdministratif
 * @version 1.0b
 */

session_start();

// Configuration file
include '../configuration.php';
// Functions
include '../inc/functions.php';

// Checking if user is logged in
if (!CheckSession()):
	exit();
endif;

// Include all objects
// TODO: Include only needed classes
foreach (glob($configuration['webroot'].'objects/*.php') as $class) { include_once $class; }

try {
	// // Retrieving activity
	$crmuser = new CRMUser();
	$crmuser->Get($_POST['id']);
	
	$crmuser->contactId = $_POST['contact'];
	$crmuser->credentialsId = $_POST['credentials'];
	$crmuser->login = $_POST['login'];
	if (strlen($_POST['password']) > 0)
		$crmuser->password = UnicrmHash($_POST['password']);
	
	// Inserting crmuser into database
	$crmuser->Save();
	
	echo 'OK';
	
} catch (Exception $e) {
	echo $e->getMessage();
}
?>